package com.sl.adapter;

import java.util.List;

import com.sl.R;
import com.sl.model.ShoppingRecord;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ShoppingActivityAdapter extends BaseAdapter {
	private Context mContext;
	private List<ShoppingRecord> mRecords;
	private LayoutInflater mInflater;

	public ShoppingActivityAdapter(Context context, List<ShoppingRecord> records){
		this.mContext = context;
		this.mRecords = records;
		this.mInflater = LayoutInflater.from(mContext);
	}
	
	@Override
	public int getCount() {
		if(mRecords == null){
			return 0;
		}
		
		return mRecords.size();
	}

	@Override
	public Object getItem(int position) {
		if(mRecords == null){
			return null;
		}
		
		return mRecords.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		
		holder = new ViewHolder();
		
		convertView = mInflater.inflate(R.layout.shopping_activities_item, null);
		
		holder.time = (TextView)convertView.findViewById(R.id.time);
		holder.mall = (TextView)convertView.findViewById(R.id.mall);
		holder.comments = (TextView)convertView.findViewById(R.id.comments);
		
		holder.time.setText(((ShoppingRecord)mRecords.get(position)).getDate());
		holder.mall.setText(((ShoppingRecord)mRecords.get(position)).getMall());
		holder.comments.setText(((ShoppingRecord)mRecords.get(position)).getComments());
		
		return convertView;
	}
	
	public final class ViewHolder {
		public TextView time;
		public TextView mall;
		public TextView comments;
	}
}
